package com.leff.cards;

import com.leff.cards.entity.QueryCard;
import com.leff.cards.entity.ResponseCard;
import com.leff.cards.request.CreateGroup;
import com.leff.cards.request.GCMRegister;
import com.leff.cards.request.GetGroups;
import com.leff.cards.request.GetInvites;
import com.leff.cards.request.InviteResponse;
import com.leff.cards.request.InviteUser;
import com.leff.cards.request.LeaveGroup;
import com.leff.cards.request.Login;
import com.leff.cards.request.RequestResult;
import com.leff.cards.request.SelectCard;
import com.leff.cards.request.SubmitCard;

public class ResponseFactory {
	
	public static RequestResult parseCommandParameters(String command, Dictionary dict) {
		
		RequestResult res = new RequestResult();
		
		if("ADD_QUERY_CARD".equals(command)) {
			String card = (String)dict.get("card");
			
			QueryCard qc = new QueryCard(card);
			
			StoreWrapper.store(qc);
			
			res.res = Dictionary.withObject("message", "You added a query card to the database: " + card);
		}
		else if("ADD_RESPONSE_CARD".equals(command)) {
			String card = (String)dict.get("card");
			
			ResponseCard rc = new ResponseCard(card);
			
			StoreWrapper.store(rc);
			
			res.res = Dictionary.withObject("message", "You added a response card to the database: " + card);
		}
		else if("LOGIN".equals(command)) {
			res = new Login(dict).doLogin();
		}
		else if("GET_GROUPS".equals(command)) {
			res = new GetGroups(dict).doGetGroups();
		}
		else if("GET_INVITES".equals(command)) {
			res = new GetInvites(dict).doGetInvites();
		}
		else if("CREATE_GROUP".equals(command)) {
			res = new CreateGroup(dict).doCreate();
		}
		else if("LEAVE_GROUP".equals(command)) {
			res = new LeaveGroup(dict).doLeave();
		}
		else if("INVITE_USER".equals(command)) {
			res = new InviteUser(dict).doInvite();
		}
		else if("INVITE_RESPONSE".equals(command)) {
			res = new InviteResponse(dict).doInviteResponse();
		}
		else if("SUBMIT_CARD".equals(command)) {
			res = new SubmitCard(dict).doSubmit();
		}
		else if("SELECT_CARD".equals(command)) {
			res = new SelectCard(dict).doSelect();
		}
		else if("REGISTER_DEVICE".equals(command)) {
			res = new GCMRegister(dict).doRegister();
		}
		else if("UNREGISTER_DEVICE".equals(command)) {
			res = new GCMRegister(dict).doUnregister();
		}
		else {
			res.setErrorResult("Command not supported");
		}
		
		return res;
	}
}
